<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/9 0009
 * Time: 3:51
 */

namespace app\Payment\controller;



use app\common\controller\Homebase;
use app\Payment\model\PayAccount as PayAccount_Model;

class Index extends Homebase
{
    //初始化
    protected function initialize()
    {
        parent::initialize();
        header('Access-Control-Allow-Origin:*');
        $this->PayAccount_Model=new PayAccount_Model;


    }
    public function index(){
        if ($this->request->isPost()) {
            $order_sn = $this->request->param('order_sn');
            if(empty($order_sn)){
                $this->error('非法访问！');
            }
            $where=['trade_sn'=>$order_sn];
            $order_res= $this->PayAccount_Model->get_one($where);
            if(empty($order_res)){
                $this->error('非法访问！');
            }
            switch ($order_res['pay_id']){
                case 1:
                  $this->sheng_futong($order_res);
                    break;
                case 2:
                   $this->alipay($order_res);
                    break;
                case 3:
                   $this->bank($order_res);
                    break;
                case 4:
                   $this->internet_banking_online($order_res);
                    break;
                case 5:
                    $this->wechat($order_res);
                    break;
                default:
                    echo '未知支付方式';
                    break;
            }
          /*  print_r($order_res );
            $this->assign('order_res',$order_res);*/

        }

    }

    //盛付通
    private function sheng_futong($data){
        print_r($data);
    }
    //支付宝
    private function alipay($data){
        $notify_url=url('payment/Notifyurl/index');
        $return_url=url('payment/Returnurl/index');
        $arr=[
            'WIDout_trade_no'=>$data['trade_sn'],
            'WIDsubject'=>$data['contactname'],
            'WIDtotal_amount'=>$data['money']*$data['quantity'],
            'WIDbody'=>$data['contactname']
        ];


        session('pay_order',$data['trade_sn']);
        //header('Location:'.$return_url);
  alipay($arr, $notify_url, $return_url);

    }



    //银行转账
    private function bank($data){
        print_r($data);
    }
    //网银在线
    private function internet_banking_online($data){
        print_r($data);
    }
    //微信支付
    private function wechat($data){
        print_r($data);
    }

}